package com.kk.nb_policy.controller.app;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.kk.nb_policy.bean.Policy;
import com.kk.nb_policy.service.PolicyService;
import com.woniuxy.boot.common.pojo.ResultObj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @Author: K
 * @Date: 2024/12/16
 */
@RestController("appPolicyController")
@RequestMapping("app/policy")
public class PolicyController {

    @Autowired
    private PolicyService policyService;

    /**
     * 添加保单
     * @param policy
     * @return
     */
    @PostMapping("add")
    ResultObj add(@RequestBody Policy policy){
        policyService.save(policy);
        return ResultObj.ok();
    }

    /**
     * 支付订单，修改保单状态
     * @param id
     * @param startTime
     * @param endTime
     * @return
     */
    @GetMapping("pay")
    ResultObj pay(@RequestParam("id") Long id, @RequestParam("startTime") LocalDateTime startTime, @RequestParam("endTime") LocalDateTime endTime){
        policyService.update(new LambdaUpdateWrapper<Policy>().eq(Policy::getId, id).set(Policy::getStartTime, startTime).set(Policy::getEndTime, endTime).set(Policy::getStatus,"b"));
        return ResultObj.ok();
    }
}

